//======================
//      图片缓存
//======================
function cache(image_url,image_key) {
	return new Promise((resolve, reject) => {
		uni.getStorage({
			key: image_key,
			success:function(res){
				console.log('缓存数据++++', res)
				resolve(res)
			
			},
			fail:function(res){
				// 本地没有缓存 需要下载 
				uni.downloadFile({
					url: image_url,
					success: (res) => {
						if (res.statusCode === 200) {
							console.log('请求数据++++', res)
							resolve(res)
							uni.setStorage({
								key:image_key,
								data:res,
								success:function(){
									
								}
							})
						}
					},
					fail: (err) =>  {
						reject(err)
					}
				}); 
			}
		})
	})
	
}

function removeCache(image_key) {
	uni.removeStorage({
		key: image_key,
		success: function () {
		
		}
	})
}

export default {
	cache,
	removeCache
} 